
//表单按钮操作

$(function(){
	// 获取ID
	var str = location.href;
	var num = str.indexOf("?");
	str = str.substr(num + 1);
	var arr = str.split("&");
	for (var i = 0; i < arr.length; i++) {
		num = arr[i].indexOf("=");
		if (num > 0) {
			name = arr[i].substring(0, num);
			value = arr[i].substr(num + 1);
			this[name] = value;
		}
	}
	
	//删除空格
	function rim(str){
        return str.replace(/\s/g, "");
 	}
	//过滤html标签
	function removeHTMLTag(str){
		var pattern1 = /[\u4e00-\u9fa5]+/g;
		/*str=str.str.replace(/\"/g,"'");*/
		str = str.match(pattern1);
		if(str==""||str==undefined){
			str="新浪微博";
		}
        return str;	
	}
	
	//打印
	$("#PrintSpecialTopic img").click(function(){
		var summary=$("#tcont").val();
		console.info(summary);
		window.location.href='downLoadBrief.do?specialId='+value+'&summary='+encodeURI(summary+'');
//		'+'summary='+;
	})
	
	
	
	
	
	//最新信息
	function showEarlist(){
				/* 	论坛 */
				$.ajax({
					url:"showEarliestFiveDataOrderByForm.do",
					data:{id:value,form:"bbs",pageNo:1,size:10},
					type:"post",
					success:function(data){
						$("#bbs").html("<a href=\"##\">论坛("+data.totalRecord+")</a>");
					}
				});

		/*  百度贴吧*/
		 
				/*$.ajax({
					url:"showEarliestFiveDataOrderByForm.do",
					data:{id:value,form:"bdtieba",pageNo:1,size:10},
					type:"post",
					success:function(data){
						$("#bdtieba").html("<a href=\"##\">百度贴吧("+data.totalRecord+")</a>");
					}
				});*/
				
		/* 博客 */
		     $.ajax({
					url:"showEarliestFiveDataOrderByForm.do",
					data:{id:value,form:"blogs",pageNo:1,size:10},
					type:"post",
					success:function(data){
						$("#blogs").html("<a href=\"##\">博客("+data.totalRecord+")</a>");
					}
				});

		/* 微博*/
				
				$.ajax({
					url:"showEarliestFiveDataOrderByForm.do",
					data:{id:value,form:"weibo",pageNo:1,size:10},
					type:"post",
					success:function(data){
						$("#weibo").html("<a href=\"##\">微博("+data.totalRecord+")</a>");
					}
				});

		/* 新闻 */
				
				$.ajax({
					url:"showEarliestFiveDataOrderByForm.do",
					data:{id:value,form:"news",pageNo:1,size:10},
					type:"post",
					success:function(data){
						$("#news").html("<a href=\"##\">新闻("+data.totalRecord+")</a>");
					}
				});
		/* 贴吧 */
				
				$.ajax({
					url:"showEarliestFiveDataOrderByForm.do",
					data:{id:value,form:"tieba",pageNo:1,size:10},
					type:"post",
					success:function(data){
						$("#tieba").html("<a href=\"##\">贴吧("+data.totalRecord+")</a>");
					}
				});
		/* 微信 */	
				$.ajax({
					url:"showEarliestFiveDataOrderByForm.do",
					data:{id:value,form:"weixin",pageNo:1,size:10},
					type:"post",
					success:function(data){
						$("#weixin").html("<a href=\"##\">微信("+data.totalRecord+")</a>");
					}
				});
			
			//加载分页
			function clicklist(form,pagenums){
				console.info("测试"+form);
				console.info("测试"+pagenums);
				$("#"+form+"zhuantipagerArea").createPage({
					current: 1,
					pageCount:pagenums,
					backFn: function(p) {
						alertEarlyList(form,p);
					}
				});
								
			}
			/*加载列表*/
			function alertEarlyList(form,pageNo){
				$.ajax({
						url:"showEarliestFiveDataOrderByForm.do",
						data:{id:value,form:form,pageNo:pageNo,size:10},
						type:"post",
						success:function(data){
							console.info("aaa");
							var obj = data.results;
							var shtml="";
							for(var i=0;i<obj.length;i++)
							{
								if(obj[i].title==undefined||obj[i].source==undefined)
								{	if(obj[i].content==undefined){
										console.info(obj[i].content);
										obj[i].title="新浪微博";
									}else{
										obj[i].title= rim(obj[i].content).substring(0,40);
									}
								
									obj[i].source="新浪微博";
								}
								shtml+="<tr><td><input type=\"checkbox\" name=\"checkbox\"  id=\"" + obj[i].id + "\" value=\"" + obj[i].form + "\" http=" + obj[i].http + "></td>"
								shtml+="<td><a target=_blank href=\"toContentpage.do?id=" + obj[i].id + "&form=" + obj[i].form + "\" style=\"text-indent:0em;\">"+ removeHTMLTag(obj[i].title)+"</a></td>"
								shtml+="<td>"+obj[i].source+"</td>"
								shtml+="<td>"+obj[i].time+"</td>"
								shtml+="<td>"+obj[i].newsdegree+"</td></tr>"
							}
							$("#list").html(shtml);   
						}
					});
			}
			//打卡页面加载第一页
			alertEarlyList("news",1);
			
			/*点击专题列表的时候切换页面，同时加载分页信息*/
			$(".breadcrumb li").on("click", function() {
							var form = $(this).attr("id"); // 获取点击元素的id
							alertEarlyList(form,1);
							var pagenums=null;
							$.ajax({
								url: "showEarliestFiveDataOrderByForm.do",
								data: {
									id: value,
									form: form,
									pageNo: 1,
									size: 10
								},
								type: "post",
								success: function(data) {
									if()
									pagenums=data.totalPage;
									//分页切换
									clicklist(form,pagenums);
								}
							})
						})
			}
			
	showEarlist();
			
	//  专题预警
	function WarningList(){
		 /*专题预警YJpagerArea --分页*/
		$.ajax({
			url: "getWarningDataBySpecialId.do",
			data: {
				specialId: value
			},
		type: "post",
			success: function(data) {
				var pg_size =data.pageSize; // 总页数
				var pg_total_count = data.totalPage; //总记录数
				console.info("预警11");
			    $("#YJpagerArea").createPage({
			        pageCount:pg_total_count,
			        current:1,
			        backFn:function(p){
			              console.log(p);
			              $.ajax({
			            	  url:"getWarningDataBySpecialId.do",
			            	  data:{specialId :value,pageNo:p,size:7},
			            	  type:"post",
			            	  success:function(data){
			            		  console.info("预警2");
			            		  var yj_results=data.results;
			            		  console.info("预警数据测试");
			            		  console.info(yj_results);
			            		  var shtml="";
			            		  for(var i=0;i<yj_results.length;i++){
			            			  if(yj_results[i].title == undefined) {
			            				  yj_results[i].title = rim(yj_results[i].content).substr(0,40);
			            				  yj_results[i].source = "新浪微博";
			            			  }
			            			  shtml+="<tr><td><input type=\"checkbox\" name=\"Warningcheckbox\"  id=\""+yj_results[i].id+"\" value=\""+yj_results[i].form+"\" /></td>";
			            			  shtml+="<td> <a target=_blank href=\"toContentpage.do?id="+yj_results[i].id+"&form="+yj_results[i].form+"\">"+yj_results[i].title+"</a></td>";
			            			  
			            			  shtml+="<td>"+yj_results[i].source+"</td>";
			            			  shtml+="<td>"+yj_results[i].time+"</td>";
										shtml+="<td>"+yj_results[i].newsdegree+"</td></tr>"
			            			 
			            		  }
			            		  $("#YJ_table").empty();
			            		  $("#YJ_table").html(shtml);
			            	  }
			              });
			        }
			    });
			}

		});
	//	
		/*专题预警 --预加载*/ 
		$.ajax({
				url:"getWarningDataBySpecialId.do",
				data:{specialId :value,pageNo:1,size:7},
				type:"post",
				success:function(data){
					var yj_results=data.results;
					var shtml="";
					for(var i=0;i<yj_results.length;i++){
						if(yj_results[i].title == undefined) {
							yj_results[i].title =rim(yj_results[i].content).substr(0,40);
							yj_results[i].source = "新浪微博";
						}
						shtml+="<tr><td><input type=\"checkbox\"  name=\"Warningcheckbox\"  id=\""+yj_results[i].id+"\" value=\""+yj_results[i].form+"\" /></td>";
						shtml+="<td> <a target=_blank href=\"toContentpage.do?id="+yj_results[i].id+"&form="+yj_results[i].form+"\">"+yj_results[i].title+"</a></td>";
						shtml+="<td><a href=\"\">"+yj_results[i].source+"</a></td>";
						shtml+="<td>"+yj_results[i].time+"</td>";
						shtml+="<td>"+yj_results[i].newsdegree+"</td></tr>"
						
					}
					$("#YJ_table").html(shtml);
				}
			});
	}

	WarningList();
			
		

	function CollectionList(){
		
		/*专题收藏  SC_table*/
		/*专题收藏 --分页*/
		$.ajax({
			url: "getCollectionDataBySpecialId.do",
			data: {
				specialId: value
			},
			type: "post",
			success: function(data) {
				var sc_results = data.results;
				console.info(sc_results);
				var pg_size =data.pageSize; // 总页数
				var pg_total_count = data.totalPage; //总页数
			     $("#scpagerArea").createPage({
			         pageCount:pg_total_count,
			         current:1,
			         backFn:function(p){
			               console.log(p);
			               $.ajax({
			            	   url:"getCollectionDataBySpecialId.do",
			            	   data:{specialId :value,pageNo:p,size:7},
			            	   type:"post",
			            	   success:function(data){
			            		   var sc_results=data.results;
			            		   console.info("舆情收藏测试");
			            		   console.info(sc_results);
			            		   var shtml="";
			            		   for(var i=0;i<sc_results.length;i++){
			            			   if(sc_results[i].title == undefined) {
			            				   sc_results[i].title = rim(sc_results[i].content).substr(0,40);
			            				   sc_results[i].source = "新浪微博";
			            			   }
			            			   shtml+="<tr>"
			            				   shtml+="<td><input type=\"checkbox\" name=\"SCcheckbox\" id=\""+ sc_results[i].id +"\" value=\""+sc_results[i].form+"\"></td>"
			            				   shtml+="<td><a target=_blank href=\"toContentpage.do?id="+sc_results[i].id+"&form="+sc_results[i].form+"\">"+sc_results[i].title+"</a></td>"
			            				   shtml+="<td>"+sc_results[i].source+"</td>"
			            				   shtml+="<td>"+sc_results[i].time+"</td>"
			            				   shtml+="<td>"+sc_results[i].newsdegree+"</td></tr>"
			            			
			            		   }
			            		   $("#SC_table").empty();
			            		   $("#SC_table").html(shtml);
			            	   }
			               });
			         }
			     });
		
			
			
			}
			
		});
		
		/*专题收藏 --预加载*/ 
		$.ajax({
			url:"getCollectionDataBySpecialId.do",
			data:{specialId :value,pageNo:1,size:7},
			type:"post",
			success:function(data){
				var sc_results=data.results;
				console.info("舆情收藏测试");
				console.info(sc_results);
				var shtml="";
				for(var i=0;i<sc_results.length;i++){
					if(sc_results[i].title == undefined) {
						sc_results[i].title = rim(sc_results[i].content).substr(0,40);
						sc_results[i].source = "新浪微博";
					}
					shtml+="<tr>"
						shtml+="<td><input type=\"checkbox\" name=\"SCcheckbox\" id=\""+ sc_results[i].id +"\" value=\""+sc_results[i].form+"\"></td>"
						shtml+="<td><a target=_blank href=\"toContentpage.do?id="+sc_results[i].id+"&form="+sc_results[i].form+"\">"+sc_results[i].title+"</a></td>"	
						shtml+="<td>"+sc_results[i].source+"</td>"
						shtml+="<td>"+sc_results[i].time+"</td>"
						shtml+="<td>"+sc_results[i].newsdegree+"</td></tr>"
				}
				$("#SC_table").html(shtml);
				
				
			}
		});
		
	}
	CollectionList();

	function BriefingList(){
		/*简报管理  JB_table*/
		
		/*简报管理  --分页*/ 
		$.ajax({
			url: "getBriefingDataBySpecialId.do",
			data: {
				specialId: value
			},
			type: "post",
			success: function(data) {
				var jb_results = data.results;
//				console.info(jb_results); 
				var pg_size =data.pageSize; // 总页数
				var pg_total_count = data.totalPage; //总记录数
			     $("#JBpagerArea").createPage({
			           pageCount:pg_total_count,
			           current:1,
			           backFn:function(p){
			                 console.log(p);
			                 $.ajax({
			                	 url: "getBriefingDataBySpecialId.do",
			                	 data: {
			                		 specialId: value,
			                		 pageNo:p,
			                		 size: 7
			                	 },
			                	 type: "post",
			                	 success: function(data) {
			                		 var jb_results = data.results;
			                		 console.info(jb_results);
			                		 var shtml = "";
			                		 for(var i = 0; i < jb_results.length; i++) {
			                			 
			                				if(jb_results[i].title == undefined) {
			                					jb_results[i].title = rim(jb_results[i].content).substr(0,40);
			                					jb_results[i].source = "新浪微博";
			            					}
			                			 shtml += "<tr>"
			                				 shtml += "<td><input type=\"checkbox\" name=\"Briefincheckbox\" id=\""+ jb_results[i].id +"\" value=\""+jb_results[i].form+"\"></td>"
			                				 shtml += "<td><a target=_blank href=\"toContentpage.do?id="+jb_results[i].id+"&form="+jb_results[i].form+"\">"+jb_results[i].title+"</a></td>"
			                				 shtml += "<td>" + jb_results[i].source + "</td>"
			                				 shtml += "<td>" + jb_results[i].time + "</td>"
			                				  shtml+="<td>"+jb_results[i].newsdegree+"</td></tr>"
			                		 }
			                		 $("#JB_table").empty();
			                		 $("#JB_table").html(shtml);
			                	 }
			                 });
			           }
			       });
			}
			
		});
		
		/*简报管理  --预加载*/ 
		$.ajax({
			url:"getBriefingDataBySpecialId.do",
			data:{specialId :value,pageNo:1,size:7},
			type:"post",
			success:function(data){
				var jb_results=data.results;
				console.info(jb_results);
				var shtml="";
				for(var i=0;i<jb_results.length;i++){
					if(jb_results[i].title == undefined) {
    					jb_results[i].title = rim(jb_results[i].content).substr(0,40);
    					jb_results[i].source = "新浪微博";
					}
					
					shtml+="<tr>"
						shtml += "<td><input type=\"checkbox\" name=\"Briefincheckbox\" id=\""+ jb_results[i].id +"\" value=\""+jb_results[i].form+"\"></td>"
						shtml += "<td><a target=_blank href=\"toContentpage.do?id="+jb_results[i].id+"&form="+jb_results[i].form+"\">"+jb_results[i].title+"</a></td>"
						shtml+="<td>"+jb_results[i].source+"</td>"
						shtml+="<td>"+jb_results[i].time+"</td>"
						  shtml+="<td>"+jb_results[i].newsdegree+"</td></tr>"
       		 
				}
				$("#JB_table").html(shtml);
			}
		});
	}

	BriefingList();
	
	$("#all").click(function(){
		if(this.checked){
			$('input:checkbox[name="checkbox"]').prop("checked", true);
		}else{
			$('input:checkbox[name="checkbox"]').prop("checked",false);
		}
		}); 

	
//添加正面
$("#addpositive").click(function(){
	var checkedObj = $('input:checkbox[name="checkbox"]:checked'); //获取当前checked的value值 如果选中多个则循环
    var state = this.value;
    var formIds = [];
    var formNames = [];
	checkedObj.each(function() { 
		 formIds.push(this.id);
		 formNames.push(this.value); 
	 });
	 $.ajax({
		 traditional: true,
		 url:"updataYQState.do",
		 data:{state:state,formIds:formIds,formNames:formNames},
		 type:"post",
		 success:function(data){
			 alert("添加正面成功");
			 $("input[type='checkbox']").prop("checked", false);
		 }
		 
	 });
})


//添加负面	
$("#addnegative").click(function(){
	var checkedObj = $('input:checkbox[name="checkbox"]:checked'); //获取当前checked的value值 如果选中多个则循环
    var state = this.value;//状态值
    var formIds = [];
    var formNames = [];
	checkedObj.each(function() { 
		 formIds.push(this.id);
		 formNames.push(this.value); 
	 });
	 $.ajax({
		 traditional: true,
		 url:"updataYQState.do",
		 data:{state:state,formIds:formIds,formNames:formNames},
		 type:"post",
		 success:function(data){
			 alert("添加负面成功");
			 $("input[type='checkbox']").prop("checked", false);
		 }
		 
	 });
	 
	
})
	
	
	
	
	
	
// 增加预警
	$("#addyj").on("click",function(){
		 var checkedObj = $('input:checkbox[name="checkbox"]:checked'); //获取当前checked的value值 如果选中多个则循环
		 console.info(checkedObj);
		 var id=new Array();
		 var form=new Array();
		 checkedObj.each(function() { 
			 var isid = this.id; 
			 var isform = this.value; 

			id.push(isid);   
			form.push(isform);
			 });
		 if(id.length!=0){
			 $.ajax({
					traditional: true,//这个设置为true，data:{"steps":["qwe","asd","zxc"]}会转换成steps=qwe&steps=asd&...
					url:"addInYQWarning.do",
					data:{specialId:value,formIds:id,formNames:form},
					type:"post",
					success:function(data){
						if(data.status==200){
							alert("纳入预警成功");
							$("input[type='checkbox']").prop("checked", false);
							WarningList();
						}
					
					}
					
				});
		 }
				
		
	});
	

// 增加收藏
	$("#addsc").on("click",function(){
		 var checkedObj = $('input:checkbox[name="checkbox"]:checked'); //获取当前checked的value值 如果选中多个则循环
		 console.info(checkedObj);
		 var id=new Array();
		 var form=new Array();
		 checkedObj.each(function() { 
			 var isid = this.id; 
			 var isform = this.value; 
			id.push(isid);
			form.push(isform);
			 });
		 if(id.length!=0){
			$.ajax({
				traditional: true,//这个设置为true，data:{"steps":["qwe","asd","zxc"]}会转换成steps=qwe&steps=asd&...
				url:"addInYQCollection.do",
				data:{specialId:value,formIds:id,formNames:form},
				type:"post",
				success:function(data){
					if(data.status==200){
						alert("纳入收藏成功");
						$("input[type='checkbox']").prop("checked", false);
						CollectionList();
					}
				}
			});
		 }
		});
	
//增加简报	
	$("#addjb").on("click",function(){
		 var checkedObj = $('input:checkbox[name="checkbox"]:checked'); //获取当前checked的value值 如果选中多个则循环
		 console.info(checkedObj);
		 var id=new Array();
		 var form=new Array();
		 checkedObj.each(function() { 
			 var isid = this.id; 
			 var isform = this.value; 

			id.push(isid);
			form.push(isform);
			 });
		 if(id.length!=0){
			 console.info(value);
			$.ajax({
				traditional: true,//这个设置为true，data:{"steps":["qwe","asd","zxc"]}会转换成steps=qwe&steps=asd&...
				url:"addInYQBriefing.do",
				data:{specialId:value,formIds:id,formNames:form},
				type:"post",
				success:function(data){
					if(data.status==200){
						alert("纳入简报成功");
						$("input[type='checkbox']").prop("checked", false);
						BriefingList();
					}
				
						
				}
			});
		 }
	});

//删除舆情
	
	$("#deleteYq").on("click",function(){
		console.log("clicked");
		 var checkedObj = $('input:checkbox[name="checkbox"]:checked'); //获取当前checked的value值 如果选中多个则循环
		 var https=new Array();
		 checkedObj.each(function() { 
			 var httpinfo=$(this).attr("http");
			 $(this).prop("http",httpinfo);
			 var ishttp = $(this).prop("http");
			 https.push(ishttp); 
			 });
		 if(https.length!=0){
			$.ajax({
				traditional: true,//这个设置为true，data:{"steps":["qwe","asd","zxc"]}会转换成steps=qwe&steps=asd&...
				url:"deleteYq.do",
				data:{versions:https},
				type:"post",
				success:function(data){
				    alert("删除成功");
				    $("input[type='checkbox']").prop("checked", false);
				    showEarlist(); 
						
				}
			});
		 }
	});

	
	
	
// 舆情收藏部分删除
	$("#CollectioAll").click(function(){
		if(this.checked){
			$('input:checkbox[name="SCcheckbox"]').prop("checked", true);
		}else{
			$('input:checkbox[name="SCcheckbox"]').prop("checked",false);
		}
		}); 
	
	$("#CollectioDelet").click(function() {
		var checkedObj = $('input[name="SCcheckbox"]:checked'); //可能有多个复选框被选中
		if(checkedObj.length != 0) {
			//获取选择信息的id和formNames
			var ids = new Array();
			var forms = new Array();
			checkedObj.each(function() {
				var id = this.id;
				var form = this.value;
				ids.push(id);
				forms.push(form);
			})
			if(ids.length != 0) {
				$.ajax({
					traditional: true,
					type: "post",
					url: "deleteFromYQCollection.do",
					data: {
						specialId: value,
						formIds: ids,
						formNames: forms
					},
					success: function(data) {
						if(data.status==200){
							alert("删除收藏成功");
							$("input[type='checkbox']").prop("checked", false);
							CollectionList();
						}
					}
					
				});
			}
		}else {
			alert("请选择你要删除的内容");
		}
	})

// 删除预警
$("#WarningAll").click(function(){
		if(this.checked){
			$('input:checkbox[name="Warningcheckbox"]').prop("checked", true);
		}else{
			$('input:checkbox[name="Warningcheckbox"]').prop("checked",false);
		}
		}); 
	
	$("#WarningDelet").click(function() {
		var checkedObj = $('input[name="Warningcheckbox"]:checked'); //可能有多个复选框被选中
		if(checkedObj.length != 0) {
			//获取选择信息的id和formNames
			var ids = new Array();
			var forms = new Array();
			checkedObj.each(function() {
				var id = this.id;
				var form = this.value;
				ids.push(id);
				forms.push(form);
			})
			if(ids.length != 0) {
				$.ajax({
					traditional: true,
					type: "post",
					url: "deleteFromYQWarning.do",
					data: {
						specialId: value,
						formIds: ids,
						formNames: forms
					},
					success: function(data) {
						if(data.status==200){
							alert("删除预警成功");
							$("input[type='checkbox']").prop("checked", false);
							WarningList(); 
						}
					}
					
					
				});
			}
		}else {
			alert("请选择你要删除的内容");
		}
	})	
	
// 删除简报
	$("#BriefingAll").click(function(){
		if(this.checked){
			$('input:checkbox[name="Briefincheckbox"]').prop("checked", true);
		}else{
			$('input:checkbox[name="Briefincheckbox"]').prop("checked",false);
		}
		}); 
	
	$("#BriefingDelet").click(function() {
		var checkedObj = $('input[name="Briefincheckbox"]:checked'); //可能有多个复选框被选中
		if(checkedObj.length != 0) {
			//获取选择信息的id和formNames
			var ids = new Array();
			var forms = new Array();
			checkedObj.each(function() {
				var id = this.id;
				var form = this.value;
				ids.push(id);
				forms.push(form);
			})
		}
				if(ids.length != 0) {
					$.ajax({
						traditional: true,
						type: "post",
						url: "deleteFromYQBriefing.do",
						data: {
							specialId: value,
							formIds: ids,
							formNames: forms
						},
						success: function(data) {
							if(data.status==200){
								alert("删除简报成功");
								$("input[type='checkbox']").prop("checked", false);
								BriefingList();
							}
						}
					
					
					});
				}
		
		else {
			alert("请选择你要删除的内容");
		}
	})		
	
	
	


});
